package ui.popup 
{
	import com.GCQuest;
	import com.Logging.CGSClientConstants;
	import com.Logging.ClientAction;
	import com.Logging.ClientActionType;
	import data.*;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import ui.button.GCButton;
	import ui.textfield.*;
	
	/**
	 * ...
	 * @author Roy
	 */
	public class GCGoalPopup extends GCGoalDisplayObject
	{
		private var _currentGoal:GCQuest;
		
		private var _miniDescriptionText:GCTextField;
		private var _detailsButton:GCButton;
		
		public function GCGoalPopup(quest:GCQuest) 
		{
			_currentGoal = quest;
			_detailsButton = new GCButton(onGoalClicked);
			_miniDescriptionText = new GCTextField();
			
			init();
		}
		
		override public function cleanUp():void
		{
			
		}
		
		override public function getQuest():GCQuest
		{
			return _currentGoal;
		}
		
		private function init():void
		{
			_detailsButton.loadGraphic(GCResources.plate, 100, 30);
			_detailsButton.loadText("Details");
			_detailsButton.width = 100;
			_detailsButton.height = 30;
			
			_miniDescriptionText.text = "New Goal";
			_miniDescriptionText.setTextFormat(GCTextField.QUEST_FORMAT);
			this.addChild(GCResources.getResource("goal"));
			this.addChild(_miniDescriptionText);
			this.addChild(_detailsButton);
			
			_detailsButton.y = this.height - _detailsButton.height;
		}
		
		/**
		 * Triggered when player clicks the goal.
		 * 
		 * If goal can be done incrementally i.e. sell at least X or buy at least X
		 * then display progress
		 */
		private function onGoalClicked(event:MouseEvent):void
		{
			
			if (GCConstants.LOGGING_DATA)
			{
				var o:Object = new Object();
				o["templateId"] = _currentGoal.templateId;
				GCPlayState.logger.LogAction(new ClientAction(ClientActionType.VIEW_GOAL, o));
			}
			
			var template:uint = _currentGoal.templateId;
			var description:String = GCQuestData.getDescriptionFromId(template);
			GCPlayState.disableScreen(new GCTextPopup(description, GCPlayState.enableScreen));
		}
		
	}
}